//
//  ContentView.swift
//  bill
//
//  Created by Eudon on 2025/6/18.
//

import SwiftUI

// 主视图，包含底部选项卡
struct ContentView: View {
    @StateObject private var transactionStore = TransactionStore()
    @State private var selectedTab = 1
    @State private var showSplash = true
    
    var body: some View {
        ZStack {
            if !showSplash {
                TabView(selection: $selectedTab) {
                    NavigationView {
                        BillView(store: transactionStore)
                    }
                    .tabItem {
                        Image(systemName: "doc.text")
                        Text("账单")
                    }
                    .tag(0)
                    
                    NavigationView {
                        TodayView(store: transactionStore)
                    }
                    .tabItem {
                        Image(systemName: "calendar")
                        Text("今天")
                    }
                    .tag(1)
                    
                    NavigationView {
                        MyView()
                    }
                    .tabItem {
                        Image(systemName: "person.crop.circle")
                        Text("我")
                    }
                    .tag(2)
                }
                .accentColor(.blue)
            }
            if showSplash {
                SplashView(isActive: $showSplash)
                    .transition(.opacity)
                    .zIndex(1)
            }
        }
    }
}

// 启动动画视图
struct SplashView: View {
    @State private var scale: CGFloat = 1.0
    @State private var opacity: Double = 1.0
    @State private var blur: CGFloat = 0.0
    @Binding var isActive: Bool
    var body: some View {
        ZStack {
            Color(.systemBackground).ignoresSafeArea()
            Text("Bill")
                .font(.system(size: 48, weight: .bold, design: .rounded))
                .foregroundColor(.primary)
                .scaleEffect(scale)
                .opacity(opacity)
                .blur(radius: blur)
        }
        .onAppear {
            // 先静止1秒
            DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
                withAnimation(.easeInOut(duration: 0.5)) {
                    scale = 2.2
                    opacity = 0.0
                    blur = 16
                }
                // 0.5秒后消散并进入主界面
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                    isActive = false
                }
            }
        }
    }
}

#Preview {
    ContentView()
} 